
import 'dart:convert';

import 'package:ichinesereader/models/class/ClassResp.dart';
import 'package:ichinesereader/models/student/StudentItem.dart';

ClassAnnouncementsResult classAnnouncementsResultFromJson(String str) => ClassAnnouncementsResult.fromJson(json.decode(str));
String classAnnouncementsResultToJson(ClassAnnouncementsResult data) => json.encode(data.toJson());
List<Announcement> announcementFromJson(String str) => List<Announcement>.from(json.decode(str).map((x) => Announcement.fromJson(x)));
String announcementToJson(List<Announcement> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class ClassAnnouncementsResult {
    ClassAnnouncementsResult({
        this.limit,
        this.page,
        this.count,
        this.list,
    });

    int? limit;
    int? page;
    int? count;
    List<Announcement>? list;

    factory ClassAnnouncementsResult.fromJson(Map<String, dynamic> json) => ClassAnnouncementsResult(
        limit: json["limit"],
        page: json["page"],
        count: json["count"],
        list: json["list"]!=null ? List<Announcement>.from(json["list"].map((x) => Announcement.fromJson(x))) : null,
    );

    Map<String, dynamic> toJson() => {
        "limit": limit,
        "page": page,
        "count": count,
        "list": list!=null? List<dynamic>.from(list!.map((x) => x.toJson())) : null,
    };
}

class Announcement {
    Announcement({
        this.id,
        this.message,
        this.point,
        this.allStudentsClass,
        this.when,
        this.announcementType,
        this.grade,
        this.bookTitle,
        this.content,
        this.type,
        this.students,
        this.teacherName,
        this.teacherUsername,
        this.comment,
        this.ack,
        this.classResp,
    });

    String? id;
    String? message;
    int? point;
    bool? allStudentsClass;
    int? when;
    String? announcementType;
    String? grade;
    String? bookTitle;
    String? content;
    String? type;
    List<StudentItem>? students;
    ClassResp? classResp;
    String? teacherName;
    String? teacherUsername;
    String? comment;
    Ack? ack;

    factory Announcement.fromJson(Map<String, dynamic> json) => Announcement(
        id: json["id"],
        message: json["message"],
        point: json["point"],
        allStudentsClass: json["allStudentsClass"],
        when: json["when"],
        announcementType: json["announcementType"] == null ? null : json["announcementType"],
        grade: json["grade"] == null ? null : json["grade"],
        bookTitle: json["bookTitle"] == null ? null : json["bookTitle"],
        content: json["content"] == null ? null : json["content"],
        type: json["type"] == null ? null : json["type"],
        students: json["students"]!=null ? List<StudentItem>.from(json["students"].map((x) => StudentItem.fromJson(x))):null,
        teacherName: json["teacherName"],
        teacherUsername: json["teacherUsername"],
        comment: json["comment"] == null ? null : json["comment"],
        ack: json["ack"]!=null ? Ack.fromJson(json["ack"]): null,
        classResp:json["classResp"]!=null ?  ClassResp.fromJson(json["classResp"]): null,
    );

    Map<String, dynamic> toJson() => {
        "id": id,
        "message": message,
        "point": point,
        "allStudentsClass": allStudentsClass,
        "when": when,
        "announcementType": announcementType == null ? null : announcementType,
        "grade": grade == null ? null : grade,
        "bookTitle": bookTitle == null ? null : bookTitle,
        "content": content == null ? null : content,
        "type": type == null ? null : type,
        "students": List<dynamic>.from(students!.map((x) => x.toJson())),
        "teacherName": teacherName,
        "teacherUsername": teacherUsername,
        "comment": comment == null ? null : comment,
          "ack": ack!=null ? ack?.toJson(): null,
        "classResp":classResp!=null ?  classResp?.toJson(): null,
    };
}

class Ack {
    Ack({
        this.read,
    });

    bool? read;

    factory Ack.fromJson(Map<String, dynamic> json) => Ack(
        read: json["read"],
    );

    Map<String, dynamic> toJson() => {
        "read": read,
    };
}